﻿using Autofac;
using System.Reflection;
using Module = Autofac.Module;

namespace rbac.api
{
    /// <summary>
    /// Autofac注册服务类
    /// </summary>
    public class AutofacModuleRegister : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            // 批量注册服务
            builder.RegisterAssemblyTypes(Assembly.Load("rbac.domain"))
                .Where(a => a.Name.EndsWith("Repository")).AsImplementedInterfaces();
            builder.RegisterAssemblyTypes(Assembly.Load("rbac.services"), Assembly.Load("rbac.contracts"))
                .Where(a => a.Name.EndsWith("Service")).AsImplementedInterfaces();
            builder.RegisterType<TokenService>();

        }
    }
}
